<?php

namespace core\lib;


class router
{
	public $controller;
	public $method;
	public function __construct()
	{
		/*
			xxx.com/index.php/controller/method
		=>  xxx.com/controller/method
			1.隐藏index.php
			2.获取URL 参数部分
			3.返回对应的控制器和方法
		*/
		$this->controller = config::get('controller', 'router');
		$this->method = config::get('method', 'router');
		if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){
			$path = $_SERVER['REQUEST_URI'];
			$path = trim($path, '/');
			$cmarr = explode('/', $path);
			$len = count($cmarr);
			if($len == 1){
				$this->controller = $cmarr[0];
			}
			else{
				$this->controller = $cmarr[0];
				$this->method = $cmarr[1];
				$start = 2;
				while($start < $len && isset($cmarr[$start+1])){
					$_GET[$cmarr[$start]] = $cmarr[$start+1];
					$start += 2;
				}
			}
		}
	}
}